/**
  * @file		gpio.c
  * @author		Naresuan University: Advance Computer System, class of 2013
  * @version	V1.0.0
  * @date		18-September-2013
  * @brief		GPIO module
  */

/* Includes ------------------------------------------------------------------*/
#include "gpio.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

GPIO_InitTypeDef GPIO_InitStructure;

/**
  * @brief		Configures the specified pin to behave either as an input or an output.
  * @param		pin			Number of the pin whose mode you wish to set
  * @param		mode		INPUT, OUTPUT, or INPUT_PULLUP.  
  * @retval		None
  */
void pinMode(int pin, int mode)
{
	/* GPIOB Periph clock enable */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

	switch(mode){
		case 0 :
			GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING ;
		case 1 :
			GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
		case 2 :
		  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
	}
		
	switch(pin){
		case 0 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
		case 1 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
		case 2 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
		case 3 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
		case 4 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
		case 5 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
		case 6 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
		case 7 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
		case 8 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
		case 9 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
		case 10 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
		case 11 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
		case 12 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
		case 13 :
			GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
	}
	
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	
}


/**
  * @brief		Reads the value from a specified digital pin, either HIGH or LOW.
  * @param		pin 		Number of the digital pin you want to read
  * @retval		HIGH or LOW.
  */
int digitalRead(int pin)
{
	switch(pin){
		case 0 :
			return GPIO_ReadInputDataBit(GPIOB,(uint16_t)pin);
	}
	
	return LOW;
	
}


/**
  * @brief		Write a HIGH or a LOW value to a digital pin.
  * @param		pin			Pin number.
  * @param		value		HIGH or LOW.
  * @retval		None
  */
void digitalWrite(int pin, int value)
{
}
